<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用jquery的方式来实现ajax</title>
</head>
<body>
     <form autocomplete="off">
        姓名:<input type="text" id="username">
         <span id="uSpan"></span>
         <br>
         <input type="submit" value="注册">
     </form>
</body>
<script src="js/jquery-3.3.1.min.js"></script>
<script>
    //给input标签设置一个消失焦点事件
    $("#username").blur(function(){
         var username = $("#username").val();
         $.ajax({
             url:"userServlet",
             async:true,
             data: "username="+username,
             type:"Get",
             dataType:"text",
             success:function(data){
                 $("#uSpan").html(data);
             },
             error:function () {
                alert("有误");
        }
         });
    });
</script>
</html>